﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Diagnostics;
using System.Configuration;

namespace YLClient.Froms
{
    /// <summary>
    /// Interaction logic for SettingManager.xaml
    /// </summary>
    public partial class SettingManager : Window
    {
        XDocument doc;
        string config;
        public SettingManager()
        {

            InitializeComponent();
            //var file = Environment.CurrentDirectory;
            //var dir = Common.getDir(file);
            //config = dir + "\\" + Process.GetCurrentProcess().ProcessName + ".exe.config";
            //doc = XDocument.Load(config);
            //var settings =
            //    doc.Element(XName.Get("configuration"))
            //    .Element(XName.Get("userSettings"))
            //    .Element(XName.Get("YLClient.Properties.Settings"))
            //    .Elements(XName.Get("setting"));
            //var ItemSaveDir = settings.ElementAt(0);
            //var loginName = settings.ElementAt(1);
            //var loginPwd = settings.ElementAt(2);
            initialUi();
        }

        private void initialUi()
        {

            txtItemSaveDir.Text = Properties.Settings.Default.ItemSaveDir;
            txtbLoginName.Text = Properties.Settings.Default.AutoLoginName;
            txtbPwd.Text = Properties.Settings.Default.AutoLoginPwd;
        }

        private void btnSetting_Click(object sender, RoutedEventArgs e)
        {
            string loginName = txtbLoginName.Text;
            string pwd = txtbPwd.Text;
            string itemSaveDir = txtItemSaveDir.Text;
            Properties.Settings.Default.ItemSaveDir = itemSaveDir;
            Properties.Settings.Default.AutoLoginName = loginName;
            Properties.Settings.Default.AutoLoginPwd = pwd;
            Properties.Settings.Default.Save();
            this.Close();
        }
    }
}
